/*    */ package com.zimbra.cs.zimlet;
/*    */ 
/*    */ import com.google.common.cache.Cache;
/*    */ import com.google.common.cache.CacheBuilder;
/*    */ import com.google.common.collect.ImmutableSet;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.soap.account.type.Prop;
/*    */ import java.util.Collections;
/*    */ import java.util.HashSet;
/*    */ import java.util.Set;
/*    */ import java.util.concurrent.TimeUnit;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class ZimletUserProperties
/*    */ {
/* 39 */   private static final Cache<String, ZimletUserProperties> CACHE = CacheBuilder.newBuilder().maximumSize(1024L).expireAfterAccess(30L, TimeUnit.MINUTES).build();
/*    */   
/*    */ 
/* 42 */   private final Set<Prop> properties = new HashSet();
/*    */   
/*    */   public static ZimletUserProperties getProperties(Account account) {
/* 45 */     String key = account.getId();
/* 46 */     ZimletUserProperties prop = (ZimletUserProperties)CACHE.getIfPresent(key);
/* 47 */     if (prop == null) {
/* 48 */       prop = new ZimletUserProperties(account);
/* 49 */       CACHE.put(key, prop);
/*    */     }
/* 51 */     return prop;
/*    */   }
/*    */   
/*    */   private ZimletUserProperties(Account account) {
/* 55 */     String[] props = account.getMultiAttr("zimbraZimletUserProperties");
/* 56 */     for (String prop : props) {
/*    */       try {
/* 58 */         this.properties.add(new Prop(prop));
/*    */       } catch (IllegalArgumentException e) {
/* 60 */         ZimbraLog.zimlet.warn("invalid property: %s", new Object[] { e.getMessage() });
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   public synchronized void setProperty(String zimlet, String key, String value) {
/* 66 */     Prop newProp = new Prop(zimlet, key, value);
/* 67 */     for (Prop prop : this.properties) {
/* 68 */       if (prop.matches(newProp)) {
/* 69 */         prop.replace(newProp);
/* 70 */         return;
/*    */       }
/*    */     }
/* 73 */     this.properties.add(newProp);
/*    */   }
/*    */   
/*    */   public synchronized Set<Prop> getAllProperties() {
/* 77 */     return ImmutableSet.copyOf(this.properties);
/*    */   }
/*    */   
/*    */   public synchronized void saveProperties(Account account) throws ServiceException {
/* 81 */     String[] props = new String[this.properties.size()];
/* 82 */     int index = 0;
/* 83 */     for (Prop prop : this.properties) {
/* 84 */       props[(index++)] = prop.getSerialization();
/*    */     }
/* 86 */     Provisioning.getInstance().modifyAttrs(account, Collections.singletonMap("zimbraZimletUserProperties", props));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/zimlet/ZimletUserProperties.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */